package com.sunxd.rule.judge;

import com.alibaba.fastjson.JSON;
import com.sunxd.rule.judge.beans.param.Condition;
import com.sunxd.rule.judge.handler.AbsConditionHandler;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * @author sun.xd
 * @description: description
 * @date 2024/10/21 15:33
 */
@Slf4j
public class ConditionJudgeUtil {

    public static Boolean doJudge(Condition condition) {
        if (Objects.isNull(condition)
                || Objects.isNull(condition.getOperatorType())
                || Objects.isNull(condition.getLeft())
                || Objects.isNull(condition.getRight())){
            log.info("param has null => param : {}", JSON.toJSONString(condition));
        }
        AbsConditionHandler handler = AbsConditionHandler.getHandler(condition.getOperatorType());
        if (Objects.isNull(handler)) {
            log.info("not find operator handler => operatorType ： {}", condition.getOperatorType());
            return Boolean.FALSE;
        }
        return handler.doJudge(condition);

    }
}
